<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  
  <link rel="shortcut icon" href="img/favicon.ico">
  <title>Collection - Java Note</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" />

  <link rel="stylesheet" href="css/theme.css" />
  <link rel="stylesheet" href="css/theme_extra.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" />
  
  <script>
    // Current page data
    var mkdocs_page_name = "Collection";
    var mkdocs_page_input_path = "Collection.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="js/jquery-2.1.1.min.js" defer></script>
  <script src="js/modernizr-2.8.3.min.js" defer></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
        <a href="." class="icon icon-home"> Java Note</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="./search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="index.html">Home</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="StringX.html">StringX</a>
                    </li>
                </ul>
                <ul class="current">
                    <li class="toctree-l1 current"><a class="reference internal current" href="Collection.html">Collection</a>
    <ul class="current">
    <li class="toctree-l2"><a class="reference internal" href="#static-methods-for-list-and-collection">Static Methods for List and Collection</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#iterable">Iterable</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#list">List</a>
        <ul>
    <li class="toctree-l3"><a class="reference internal" href="#arraylist">ArrayList</a>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#linkedlist">LinkedList</a>
    </li>
        </ul>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#comparable">Comparable</a>
        <ul>
    <li class="toctree-l3"><a class="reference internal" href="#comparator">Comparator</a>
    </li>
        </ul>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#vector">Vector</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#queue">Queue</a>
        <ul>
    <li class="toctree-l3"><a class="reference internal" href="#deque">Deque</a>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#linkedlist_1">LinkedList</a>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#priorityqueue">PriorityQueue</a>
    </li>
        </ul>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#set">set</a>
        <ul>
    <li class="toctree-l3"><a class="reference internal" href="#linkedhashset">LinkedHashSet</a>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#treeset">TreeSet</a>
    </li>
        </ul>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#map">map</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#singleton">Singleton</a>
    </li>
    </ul>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="IO.html">IOFile</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="Lambda.html">Lambda</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="Generic.html">Generic</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="Stream.html">Stream</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="Atomic.html">Atomic</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="Reflect.html">Reflect</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="JavaFX.html">JavaFX</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="Sundry.html">Sundry</a>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href=".">Java Note</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href=".">Docs</a> &raquo;</li>
    
      
    
    <li>Collection</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h2 id="collection">Collection</h2>
<blockquote>
<p><code>interface</code></p>
</blockquote>
<ol>
<li>a collection of elements</li>
<li>storing key/value pairs</li>
</ol>
<p><img alt="map" src="Collection/image-20201016111929267.png" /></p>
<h3 id="static-methods-for-list-and-collection">Static Methods for List and Collection</h3>
<p><img alt="StaticMethods" src="Collection/image-20201030113037593.png" /></p>
<h3 id="iterable">Iterable</h3>
<p><img alt="iterable" src="Collection/image-20201030095229138.png" /></p>
<h3 id="list">List</h3>
<p><img alt="List" src="Collection/image-20201030104216985.png" /></p>
<h4 id="arraylist">ArrayList</h4>
<blockquote>
<p><strong>vector</strong> in C++ like container</p>
<p><strong>resizable-array</strong></p>
</blockquote>
<h4 id="linkedlist">LinkedList</h4>
<blockquote>
<p><strong>linked list</strong></p>
</blockquote>
<h3 id="comparable">Comparable</h3>
<h4 id="comparator">Comparator</h4>
<blockquote>
<p>a functional interface</p>
<p>support a <code>compare</code> method</p>
</blockquote>
<h3 id="vector">Vector</h3>
<blockquote>
<p>same as <code>ArrayList</code></p>
<p>contains <strong>synchronized</strong> methods</p>
</blockquote>
<p><img alt="Vector" src="Collection/image-20201030114104510.png" /></p>
<h3 id="queue">Queue</h3>
<blockquote>
<p>interface</p>
</blockquote>
<h4 id="deque">Deque</h4>
<h4 id="linkedlist_1">LinkedList</h4>
<h4 id="priorityqueue">PriorityQueue</h4>
<p><img alt="construct" src="Collection/image-20201030114531966.png" /></p>
<h3 id="set">set</h3>
<blockquote>
<p>Three concrete classes</p>
<p><code>HashSet</code> <code>LinkedHashSet</code> <code>TreeSet</code></p>
</blockquote>
<p><img alt="set" src="Collection/image-20201030171247302.png" /></p>
<h4 id="linkedhashset">LinkedHashSet</h4>
<blockquote>
<p><code>LinkedHashSet</code>contains all things in the order in which are inserted</p>
<p>If not mind the sequence the elements are inserted use <strong>HashSet</strong> instead of <strong>LinkedHashSet</strong></p>
</blockquote>
<h4 id="treeset">TreeSet</h4>
<blockquote>
<p>provide <code>first()</code> <code>last()</code></p>
<table>
<thead>
<tr>
<th>method</th>
<th>return a portion of the set whose elements are</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>headSet(toElement)</code></td>
<td>less than <strong>toElement</strong></td>
</tr>
<tr>
<td><code>tailSet(fromElement)</code></td>
<td>greater than <strong>fromElement</strong></td>
</tr>
</tbody>
</table>
</blockquote>
<table>
<thead>
<tr>
<th>method</th>
<th>desc</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>pollFirst()</code></td>
<td>remove and return the first element</td>
</tr>
<tr>
<td><code>pollLast()</code></td>
<td>remove and return the last element</td>
</tr>
</tbody>
</table>
<h3 id="map">map</h3>
<blockquote>
<p><code>Entry</code> is same to <code>pair</code> in <strong>C++</strong></p>
</blockquote>
<p><img alt="viewMap" src="Collection/image-20201030175143694.png" /></p>
<p><img alt="interfaceMap" src="Collection/image-20201030175215109.png" /></p>
<p><img alt="MapUML" src="Collection/image-20201030175509995.png" /></p>
<h3 id="singleton">Singleton</h3>
<p><img alt="Singleton" src="Collection/image-20201030181157220.png" /></p>
<blockquote>
<p>three constants in <strong>Collections</strong> </p>
<p><italic><font size=5 color=DeepSkyBlue>EMPTY_SET<br> EMPTY_LIST<br> EMPTY_MAP</font></italic></p>
<p><strong>unmodifiable</strong> : <strong><em>read-only</em></strong> view for collections</p>
</blockquote>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="IO.html" class="btn btn-neutral float-right" title="IOFile">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="StringX.html" class="btn btn-neutral" title="StringX"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
      
        <span><a href="StringX.html" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="IO.html" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '.';</script>
    <script src="js/theme.js" defer></script>
      <script src="search/main.js" defer></script>
    <script defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>
</html>
